var randomLoc = Math.floor(Math.random() * 5);
var location1 = randomLoc + 1;
var location2 = location1 + 1;
var location3 = location2 + 1;
var guess;
var hits = 0;
var guesses = 0;
var isSunk = false;

while (isSunk == false) {
    guess = prompt("准备, 瞄准, 开火! (输入0-6的一个数字):");
    if(guess < 0 || guess > 6) {
        alert("请输入合法的数字!");
    } else {
        guesses = guesses + 1;
        if (guess == location1 || guess ==location2 || guess == location3) {
            hits += 1;
            alert("HIT!");
            if (hits == 3) {
                isSunk = true;
                alert("你击沉了我的战舰!");
            }
        } else {
            alert("MISS");
        }
    }
}

var stats = "你花了" + guesses +"次击沉战舰, " + "你的准确度是" + (3/guesses);
alert(stats);